Imports System.Drawing
Imports System.Drawing.Drawing2D


<Serializable()> Public Class ctlCampToolSuite

    Public Event ButtonClicked(ByVal sender As cButton)
    Private butts As New Collection

    '// here, we'll make all dem butties
    Private _new As New cButton
    Private _exit As New cButton
    Private _open As New cButton
    Private _save As New cButton
    Private _logon As New cButton
    Private _moderator As New cButton
    Private _nextplayer As New cButton
    Private _deploy As New cButtonToggle
    Private _manager As New cButton
    Private _resources As New cButton
    Private _victory As New cButton
    Private _log As New cButton


    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        MakeADaButtons()
    End Sub

#Region "Properties"

    Public ReadOnly Property LogButton() As cButton
        Get
            Return _log
        End Get
    End Property

    Public ReadOnly Property logonButton() As cButton
        Get
            Return _logon
        End Get
    End Property

    Public ReadOnly Property victoryButton() As cButton
        Get
            Return _victory
        End Get
    End Property

    Public ReadOnly Property resourcesButton() As cButton
        Get
            Return _resources
        End Get
    End Property

    Public ReadOnly Property managerButton() As cButton
        Get
            Return _manager
        End Get
    End Property

    Public ReadOnly Property deployButton() As cButtonToggle
        Get
            Return _deploy
        End Get
    End Property

    Public ReadOnly Property nextPlayerButton() As cButton
        Get
            Return _nextplayer
        End Get
    End Property

    Public ReadOnly Property moderatorButton() As cButton
        Get
            Return _moderator
        End Get
    End Property

    Public ReadOnly Property saveButton() As cButton
        Get
            Return _save
        End Get
    End Property

    Public ReadOnly Property exitButton() As cButton
        Get
            Return _exit
        End Get
    End Property

    Public ReadOnly Property openButton() As cButton
        Get
            Return _open
        End Get
    End Property
#End Region

    Public Sub ResetToNormalColors()
        Try
            For Each butt As cButton In butts
                butt.MouseOut()
            Next

        Catch ex As Exception
        End Try
    End Sub

    Public Property Buttons() As Collection
        Get
            Return butts
        End Get
        Set(ByVal value As Collection)
            butts = value
        End Set
    End Property

    Private Sub MakeADaButtons()
        Dim buttSize As New Size(52, 24)
        Dim curPoint As New Point(4, 2)

        '// easy to change the colors: right here
        '   Dim butt As New cButton
        '   Dim fastCo As New cButtonColorProperties
        '   fastCo.mouseovercolor1 = Color.Firebrick
        '   fastCo.mouseovercolor2 = Color.Pink
        '   butt.colorProperties = fastCo
        '   butt.init(buttSize, curPoint, "Exit")
        '   butt.Enabled = True
        '   butts.Add(butt)
        '   AddHandler butt.MouseChanged, AddressOf mousechanged

        CreateButton(_exit, buttSize, curPoint, "Exit")

        curPoint.X += buttSize.Width + 2
        CreateButton(_new, buttSize, curPoint, "New")

        curPoint.X += buttSize.Width + 2
        CreateButton(_open, buttSize, curPoint, "Open")

        curPoint.X += buttSize.Width + 2
        CreateButton(_save, buttSize, curPoint, "Save", False)

        curPoint.X += buttSize.Width + 6
        buttSize.Width += 14
        CreateButton(_moderator, buttSize, curPoint, "Moderator", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_logon, buttSize, curPoint, "Log On", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_nextplayer, buttSize, curPoint, "Next Player", False)

        curPoint.X += buttSize.Width + 2
        Dim uncheckCol As New cButtonColorProperties
        uncheckCol.mouseovercolor1 = Color.OrangeRed
        uncheckCol.mouseovercolor2 = Color.LightYellow
        uncheckCol.backColor1 = Color.DarkRed
        uncheckCol.backColor2 = Color.Tomato
        _deploy.uncheckedColor = uncheckCol
        _deploy.checked = False
        CreateButton(_deploy, buttSize, curPoint, "Deploy", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_manager, buttSize, curPoint, "Manager", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_resources, buttSize, curPoint, "Resources", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_victory, buttSize, curPoint, "Campaign", False)

        curPoint.X += buttSize.Width + 2
        CreateButton(_log, buttSize, curPoint, "Log", False)

    End Sub

    Private Sub CreateButton(ByRef b As cButton, ByVal bsize As Size, ByVal location As Point, ByVal text As String, Optional ByVal enabled As Boolean = True)

        Try
            b.init(bsize, location, text)
            b.Enabled = enabled
            butts.Add(b)
            AddHandler b.MouseChanged, AddressOf mousechanged
        Catch ex As Exception

        End Try
    End Sub

    Public Sub DoPaint()
        Try
            DoPaint(pnlClient.CreateGraphics)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub DoPaint(ByRef g As Graphics)
        For Each b As cButton In butts
            b.DrawButton(g)
        Next

    End Sub

    Private Sub pnlClient_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlClient.MouseLeave
        For Each b As cButton In butts
            b.MouseOut()
        Next
    End Sub

    Private Sub pnlClient_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlClient.MouseMove
        For Each b As cButton In butts
            b.MouseMove(e)
        Next

    End Sub

    Private Sub pnlClient_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlClient.MouseUp
        For Each b As cButton In butts
            If b.MouseClickIn(e) = True Then
                If TypeOf b Is cButtonToggle Then DirectCast(b, cButtonToggle).checked = Not DirectCast(b, cButtonToggle).checked
                RaiseEvent ButtonClicked(b)
                Exit Sub
            End If
        Next
    End Sub

    Private Sub pnlClient_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlClient.Paint
        e.Graphics.DrawImage(My.Resources.LUCorner, 0, 0)

        e.Graphics.DrawImage(My.Resources.LLCorner, 0, pnlClient.Height - My.Resources.LLCorner.Height)
        DoPaint(e.Graphics)
    End Sub

    Private Sub mousechanged()
        DoPaint(pnlClient.CreateGraphics)
    End Sub
End Class
